package com.xiao.controller;

import com.xiao.domain.ResponseResult;
import com.xiao.domain.constants.BlogCommentConstants;
import com.xiao.domain.pojo.BlogComment;
import com.xiao.service.BlogCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(("/comment"))
@Api(tags = "评论控制层")
public class BlogCommentController {

    @Autowired
    BlogCommentService blogCommentService;

    @GetMapping("/commentList")// 因为是 get 请求 不是 RestFul 所以不需要使用 @PathVariable
    @ApiOperation("根据文章ID,获取评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId",value = "文章ID"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小")
    })
    public ResponseResult getCommentList( Long articleId, Integer pageNum, Integer pageSize){
        ResponseResult result = blogCommentService.commentList(BlogCommentConstants.COMMENT_TYPE_ARTICLE,articleId, pageNum, pageSize);
        return result;
    }

    @PostMapping//这个类的请求就是 @RequestMapping(("/comment"))  所以这里不用谢请求路径。
    @ApiOperation(value = "发表评论",notes = "包括了文章和友链评论,通过请求体中的，type 来区分是对什么评论")
    @ApiImplicitParam(name = "comment",value = "评论实体类")
    public ResponseResult addComment(@RequestBody BlogComment comment){// 告诉 Spring 他是一个请求体,用实体类接收请求;不是 get 拼接的请求 如上: http://localhost:7777/comment/commentList?pageNum=1&pageSize=10&articleId=1
        ResponseResult result = blogCommentService.addComment(comment);
        return result;
    }


    @GetMapping("/linkCommentList")// 因为是 get 请求 不是 RestFul 所以不需要使用 @PathVariable
    @ApiOperation("根据文章ID,获取评论列表")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "pageNum" ,value = "页号") ,
                    @ApiImplicitParam(name = "pageSize" ,value = "每页大小")
    })
    public ResponseResult getLinkCommentList(Integer pageNum, Integer pageSize){
        ResponseResult result = blogCommentService.commentList(BlogCommentConstants.COMMENT_TYPE_LINK,null, pageNum, pageSize);
        return result;
    }

}